package com.my.socket.bio.v7;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.Socket;

/**
 * Created by ZhongGang
 * at 2018/6/28 18:26
 */
public class Connection {
    private static final Logger LOGGER = LoggerFactory.getLogger(Connection.class);

    private int id;
    private Socket socket;

    public Connection(int id, Socket socket) {
        this.id = id;
        this.socket = socket;
    }

    public int getId() {
        return id;
    }

    public Socket getSocket() {
        return socket;
    }

    public void close() {
        try {
            this.socket.close();
        } catch (IOException e) {
            LOGGER.error("exception caught, the error is {}", e.getMessage());
        }
    }

    @Override
    public String toString() {
        return "Connection{" +
                "id=" + id +
                ", socket=" + socket +
                '}';
    }
}
